package com.admin.business.background.venusOaLeaveApproval;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 考勤请假补卡审批表
 * @create: 2023-10-31 16:37:07
 **/
@Service("venusOaLeaveApprovalService")
@Slf4j
public class VenusOaLeaveApprovalService{

    @Resource
    VenusOaLeaveApprovalDao venusOaLeaveApprovalDao;

    /**
     * 添加考勤请假补卡审批表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - pid:申请表id
     *                   - approval_grade:审批等级
     *                   - pending_approval:待审批人
     *                   - already_approval:已审批人
     *                   - approval_state:审批状态(0 待审批 1 同意 2 拒绝 3 未审批 )
     *                   - approval_time:审批时间
     *                   - approval_opinion:审批意见
     *                   - begin_time:创建时间
     *                   - state:状态(0正常 1删除)
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return addVenusOaLeaveApproval(CDO cdoRequest) {
        venusOaLeaveApprovalDao.addVenusOaLeaveApproval(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新考勤请假补卡审批表数据
     *
     * @param cdoRequest - id:主键id
     *                   - pid:申请表id
     *                   - approval_grade:审批等级
     *                   - pending_approval:待审批人
     *                   - already_approval:已审批人
     *                   - approval_state:审批状态(0 待审批 1 同意 2 拒绝 3 未审批 )
     *                   - approval_time:审批时间
     *                   - approval_opinion:审批意见
     *                   - begin_time:创建时间
     *                   - state:状态(0正常 1删除)
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return updateVenusOaLeaveApprovalById(CDO cdoRequest) {
        venusOaLeaveApprovalDao.updateVenusOaLeaveApprovalById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除考勤请假补卡审批表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return deleteVenusOaLeaveApprovalById(CDO cdoRequest){
        int count = venusOaLeaveApprovalDao.deleteVenusOaLeaveApprovalById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除考勤请假补卡审批表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return deleteVenusOaLeaveApproval(CDO cdoRequest) {
        int count = venusOaLeaveApprovalDao.deleteVenusOaLeaveApproval(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取考勤请假补卡审批表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return getVenusOaLeaveApprovalById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaLeaveApprovalDao.getVenusOaLeaveApprovalById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取考勤请假补卡审批表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return getVenusOaLeaveApprovalListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaLeaveApprovalDao.getVenusOaLeaveApprovalListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaLeaveApprovalDao.getVenusOaLeaveApprovalCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取考勤请假补卡审批表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 16:37:07
     */
    @OpenApi
    public Return getVenusOaLeaveApprovalListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaLeaveApprovalDao.getVenusOaLeaveApprovalListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaLeaveApprovalDao.getVenusOaLeaveApprovalCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
